package com.samxcode.leetcode;

/**
 * Given a sorted array, remove the duplicates in place such that each element appear only once and
 * return the new length.
 * 
 * Do not allocate extra space for another array, you must do this in place with constant memory.
 * 
 * @author Sam
 *
 */
public class RemoveDuplicatesFromArray {

    public int removeDuplicates(int[] A) {
        if (A.length == 0) return 0;
        int i = 0;
        for (int j = 1; j < A.length; j++) {
            if (A[i] != A[j]) {
                A[++i] = A[j];
            }
        }
        return i + 1;
    }
}
